import { createRouter, createWebHashHistory } from 'vue-router'
import Login from '../views/auth/login.vue'
import Index from '../views/Index.vue'
import userIndex from '@/views/user/Index.vue'
import cloudDiskIndex from '@/views/cloudDisk/Index.vue'
import docIndex from '@/views/doc/Index.vue'
import moreIndex from '@/views/more/Index.vue'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'index',
      component: Index,
    },
    {
      path: '/auth/login',
      name: 'auth-login',
      component: Login,
    },
    {
      path: '/user/index',
      name: 'user-index',
      component: userIndex,
    },
    {
      path: '/cloud-disk/index',
      name: 'cloud-disk-index',
      component: cloudDiskIndex,
    },
    {
      path: '/doc/index',
      name: 'doc-index',
      component: docIndex,
    },
    {
      path: '/more/index',
      name: 'more-index',
      component: moreIndex,
    },
  ],
})
router.beforeEach((to, from) => {
  if (to.path !== '/auth/login' && !window.idLogin) {
    return router.replace({
      name: 'auth-login',
    })
  }
})

export default router
